import request from 'umi-request';
import moment from 'moment';

export async function queryResignationList(params = {},rurnoverStatus) {
  let { hiredate, ...restParams } = params;
  let hiredateStart = hiredate?.length>1 ? moment(hiredate[0]).format('YYYY-MM-DD') : null;
  let hiredateEnd = hiredate?.length>1 ? moment(hiredate[1]).format('YYYY-MM-DD') : null;
  return request('/hr-ssc/api/api-admin/dimission/queryDimissionInfoList', {
    method: 'get',
    params: {
      rurnoverStatus,
      hiredateStart,
      hiredateEnd,
      pageNum: params.current,
      ...restParams
    },
  }).then((res) => {
    const data = res.data;
    return {
      current: data.currPage,
      data: data.list,
      pageSize: data.pageSize,
      success: true,
      total: data.totalCount,
    };
  });
}

export async function saveResignationInfo(params) {
  return request('/hr-ssc/api/api-admin/dimission/saveDimissionInfo', {
    method: 'POST',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function resignApplyBpm(params) {
  return request('/hr-ssc/api/api-admin/bpm/dimissionApplyBpm', {
    method: 'GET',
    params: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteDimissionInfo(id) {
  return request(`/hr-ssc/api/api-admin/dimission/deleteDimissionInfo`, {
    method: 'delete',
    params: {id},
  }).then((res) => {
    return res;
  });
}

export async function getResignationId(userCode) {
  return request(`/hr-ssc/api/api-admin/dimission/getEmployessInfoByCode/${userCode}`, {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

